<template>
  <div>
    <van-button type="default" @click="start">开始答题</van-button>
    <van-dialog v-model="show_subscribe" title="请关注公众号参与活动">
      <div><img :src="info.subscribe_code_img" style="width:100%; margin: 20px auto;" />
      <p style="text-align:center; line-height:30px; padding-bottom:10px">dsadssadsad</p>
      </div>
    </van-dialog>
    <van-dialog v-model="show" title="请使用微信打开" :show-confirm-button="false">
      <Qcode></Qcode>
    </van-dialog>
    
  </div>
</template>

<script>
import Qcode from '@/components/qcode.vue'
import { share } from '@/api/app.js'
import { login } from '@/api/auth'
import { getUrl, isWeiXin } from '@/utils/app'

export default {
  name: 'Home',
  components: {Qcode},
  data () {
    return {
      show: false,
      show_subscribe: false,
      info: this.$store.state.acc,
      user: this.$store.state.user,
    }
  },
  created() {
    if(!isWeiXin())this.show = true
    
  },
  methods: {
    start() {
      //检查是否需要强制关注
      if(this.info.is_subscribe == 1 && this.user.is_subscribe == 0) {//跳转微信授权登录
        this.show_subscribe = true
        return
      }
      //判断用户答题次数
      if(this.user.number == 0) {
        let message = '答题机会已经用完，感谢再来参与'
        if(this.info.share_add_number >0) {// 该活动分享可以增加机会，提示语不同
          message = '答题机会已经用完，分享给好友获取答题机会'
        }
        this.$dialog.confirm({
          message: message,
        });
        return 
      }
      //跳转到答题页面
      this.$router.push({ name: 'DatiView', params: { q: this.info.code }})
    }
  }
}
</script>
